package com.wushi.lenovo.asia5b.app_widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * Created by zhangyuncai on 2019/1/17.
 */
public class ErrorTextView extends android.support.v7.widget.AppCompatTextView {

    public ErrorTextView(Context context) {
        super(context);
    }

    public ErrorTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public ErrorTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    public void setBindEditText(TextView editText) {

        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                setVisibility(GONE);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    public void setBindEditText(TextView... textViews) {

        for (TextView textView : textViews) {
            textView.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    setVisibility(GONE);
                }

                @Override
                public void afterTextChanged(Editable s) {

                }
            });
        }

    }
}
